import uuid
from django.db import models

"""
Django 数据库迁移命令: 
python manage.py makemigrations
python manage.py migrate
.venv\Scripts\activate
"""


# 订单列表
class OrderList(models.Model):
    order_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)



# 子订单
class SubOrder(models.Model):
    sub_order_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    order_id = models.ForeignKey(OrderList, on_delete=models.CASCADE, related_name='sub_orders')
    # 子订单名称
    sub_order_name = models.CharField(max_length=255)
    # 子订单编号
    sub_order_no = models.CharField(max_length=255)
    # 价格
    price = models.DecimalField(max_digits=10, decimal_places=2, default=0, null=True, blank=True)
    # 保证金
    margin = models.DecimalField(max_digits=10, decimal_places=2, default=0, null=True, blank=True)
    # 创建时间
    create_time = models.DateTimeField(auto_now_add=True)
    # 更新时间
    update_time = models.DateTimeField(auto_now=True)



# 手机号表
class PhoneNumber(models.Model):
    phone_number_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    # 手机号
    phone = models.CharField(max_length=20, unique=True)
    # 名称
    name = models.CharField(max_length=255)
    # 最大接单量
    max_orders = models.IntegerField(default=2)
    # 创建时间
    create_time = models.DateTimeField(auto_now_add=True)
    # 更新时间
    update_time = models.DateTimeField(auto_now=True)


# 手机号订单关联表
class PhoneNumberOrder(models.Model):
    STATUS_CHOICES = (
        ('pending', '使用中'),
        ('completed', '已完成'),
    )
    phone_order_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    # 关联手机号
    phone_number = models.ForeignKey(PhoneNumber, on_delete=models.CASCADE, related_name='phone_orders')
    # 订单ID
    order_id = models.CharField(max_length=255)
    # 状态
    status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='pending')
    # 备注
    remark = models.TextField(blank=True, null=True)
    # 创建时间
    create_time = models.DateTimeField(auto_now_add=True)
    # 更新时间
    update_time = models.DateTimeField(auto_now=True)




# 订单表-第二版本
class OrderListV2(models.Model):
    # 订单状态选项 - 数字表示
    STATUS_CHOICES = (
        (1, '待接手'),
        (2, '代练中'),
        (3, '待验收'),
        (4, '撤销中'),
        (5, '撤销完成'),
        (6, '仲裁中'),
        (7, '已仲裁'),
        (8, '锁定中'),
        (9, '已结算'),
        (10, '订单异常'),
        (11, '已取消'),
        (12, '待发布'),
    )
    
    order_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    # 1. 代练通订单ID
    dailiantong_order_id = models.CharField(max_length=255, blank=True, null=True)
    # 代练丸子ID
    dailianwangzi_order_id = models.CharField(max_length=255, blank=True, null=True)
    # 2. 订单名称
    order_name = models.CharField(max_length=255, blank=True, null=True)
    # 3. 接单价格
    receiving_price = models.DecimalField(max_digits=10, decimal_places=2, default=0, null=True, blank=True)
    # 4. 接单保证金
    receiving_margin = models.DecimalField(max_digits=10, decimal_places=2, default=0, null=True, blank=True)
    # 5. 接单效率金
    receiving_efficiency_fee = models.DecimalField(max_digits=10, decimal_places=2, default=0, null=True, blank=True)
    # 6. 接单代练时间
    receiving_delivery_time = models.CharField(max_length=255, blank=True, null=True)
    # 7. 接单区服
    receiving_server = models.CharField(max_length=255, blank=True, null=True)
    # 8. 发单价格
    posting_price = models.DecimalField(max_digits=10, decimal_places=2, default=0, null=True, blank=True)
    # 9. 发单安全金
    posting_security_fee = models.DecimalField(max_digits=10, decimal_places=2, default=0, null=True, blank=True)
    # 10. 发单效率金
    posting_efficiency_fee = models.DecimalField(max_digits=10, decimal_places=2, default=0, null=True, blank=True)
    # 11. 订单完成收益
    completed_profit = models.DecimalField(max_digits=10, decimal_places=2, default=0, null=True, blank=True)
    # 12. 订单没有完成收益
    uncompleted_profit = models.DecimalField(max_digits=10, decimal_places=2, default=0, null=True, blank=True)
    # 13. 订单状态
    status = models.IntegerField(choices=STATUS_CHOICES, default=12)
    # 14. 创建时间
    create_time = models.DateTimeField(auto_now_add=True)
    # 15. 更新时间
    update_time = models.DateTimeField(auto_now=True)
    # 16. 角色名
    character_name = models.CharField(max_length=255, blank=True, null=True)
    # 17. 号主账号
    account_owner = models.CharField(max_length=255, blank=True, null=True)
    # 18. 号主密码
    account_password = models.CharField(max_length=255, blank=True, null=True)
    # 19. 号主手机
    owner_phone = models.CharField(max_length=20, blank=True, null=True)
    # 20. 备注
    remark = models.TextField(blank=True, null=True)
    
    





